
package com.flowmodule.dao;
import com.flowmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbFlowTypeDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbFlowType tbFlowType=null;
    private List<TbFlowType> tbFlowTypeList=null;

    public boolean add(TbFlowType inTbFlowType){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_FlowType(FlowTypeName,UserId) values(?,?)";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlowType.getFlowTypeName());
        pt.setInt(2,inTbFlowType.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inFlowTypeId){
        return UtilDAO.del("Tb_FlowType", "FlowTypeId", inFlowTypeId);
    }
    public boolean edit(TbFlowType inTbFlowType){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_FlowType set  FlowTypeName=?,UserId=?,CreateTime=getdate()  where FlowTypeId=?";
        pt = conn.prepareStatement(sql);
        pt.setString(1,inTbFlowType.getFlowTypeName());
        pt.setInt(2,inTbFlowType.getUserId());
        pt.setInt(3,inTbFlowType.getFlowTypeId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbFlowType getTbFlowTypeByFlowTypeId(int inFlowTypeId) {
        tbFlowType=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowType where FlowTypeId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inFlowTypeId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbFlowType == null)tbFlowType = getTbFlowType(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowType;
    }
    public List<TbFlowType> getTbFlowTypeAll() {
        tbFlowTypeList=new ArrayList<TbFlowType>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowType";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowTypeList.add(getTbFlowType(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowTypeList;
    }
    public List<TbFlowType> getTbFlowTypeAll(VskPage vp) {
        tbFlowTypeList=new ArrayList<TbFlowType>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_FlowType";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_FlowType", "FlowTypeId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbFlowTypeList.add(getTbFlowType(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbFlowTypeList;
    }
    public TbFlowType getTbFlowType(ResultSet rs) throws Exception{
        TbFlowType tbFlowType = new TbFlowType();
        tbFlowType.setFlowTypeId(rs.getInt("FlowTypeId"));
        tbFlowType.setFlowTypeName(rs.getString("FlowTypeName"));
        tbFlowType.setUserId(rs.getInt("UserId"));
        tbFlowType.setCreateTime(rs.getString("CreateTime"));
        return tbFlowType;
    }
}
